package com.wxx.util;

import com.google.common.collect.Maps;
import com.wxx.common.Const;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.Map;

/**
 * @author wangxiaoxiao
 */
@Getter
@Setter
public class JsonData {

    /**
     * 自定义返回数据
     * @param code
     * @param msg
     * @param object
     * @return
     */
    public static Map returnAll(int code, String msg,Object object) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("code", code);
        map.put("msg",msg);
        map.put("data",object);
        return map;
    }

    public static Map success(Object object, String msg) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("code", Const.SUCCESS_CODE);
        map.put("msg",msg);
        map.put("data",object);
        return map;
    }

    public static Map success(Object object) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("code", Const.SUCCESS_CODE);
        map.put("msg", Const.OPREATE_MSG_SUCCESS);
        map.put("data",object);
        return map;
    }

    public static Map success(Object object,Object extra) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("code", Const.SUCCESS_CODE);
        map.put("msg", Const.OPREATE_MSG_SUCCESS);
        map.put("data",object);
        map.put("extra",extra);
        return map;
    }

    public static Map success() {
        Map<String, Object> map = Maps.newHashMap();
        map.put("code", Const.SUCCESS_CODE);
        map.put("msg", Const.OPREATE_MSG_SUCCESS);
        return map;
    }

    /**
     * 失败返回的数据
     * @param msg
     * @return
     */
    public static Map fail(String msg) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("code", Const.ERROR_CODE);
        map.put("msg",msg);
        return map;
    }

    /**
     * 增删改查返回的map
     * @param integer
     * @return
     */
    public static Map returnMap(Integer integer){
        Map map = Maps.newHashMap();
        if (integer>0){
            map.put("code", Const.SUCCESS_CODE);
            map.put("msg", Const.OPREATE_MSG_SUCCESS);
        }else{
            map.put("code", Const.ERROR_CODE);
            map.put("msg", Const.OPREATE_MSG_ERROR);
        }
        return map;
    }

    /**
     * 增删改查返回的map
     * @param integer
     * @return
     */
    public static Map returnMap(Integer integer,String msg){
        Map map = Maps.newHashMap();
        if (integer>0){
            map.put("code", Const.SUCCESS_CODE);
            map.put("msg",msg);
        }else{
            map.put("code", Const.ERROR_CODE);
            map.put("msg",msg);
        }
        return map;
    }

    /**
     * layui 列表返回的map
     * @return
     */
    public static Map returnLayuiMap(List list, Integer count){
        Map map = Maps.newHashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("data",list);
        map.put("count",count);
        return map;
    }

}
